using System;
using System.Data;
using System.Collections;
using System.Configuration;
using System.IO;
using System.Text;
using System.Xml;

namespace Config
{
    public sealed class AppConfig
    {
        public static string g_strConnectionStringSqlClient = GetConn();
        public static string g_UDPIPAddress = ReadItem("UDP", "UDPAddress");
        public static string g_UDPPort = ReadItem("UDP", "UDPPort");

        private static string GetConn()
        {
            string strDBAddress = ReadItem("Database", "DBAddress");
            string strDBName = ReadItem("Database", "DBName");
            string strDBUserName = ReadItem("Database", "DBUser");
            string strPwd = ReadItem("Database", "DBPwd");

            string strConn = "server=" + strDBAddress + "; Initial Catalog=" + strDBName + ";User Id=" + strDBUserName + "; Password=" + strPwd + ";";

            return strConn;
        }

        private static string ReadItem(string strType, string strKey)
        {
            string strValue = "";
            XmlDocument doc = new XmlDocument();
            doc.Load(@"Config.xml");
            XmlNode root = doc.SelectSingleNode("SetUp");

            XmlNode xn = root.SelectSingleNode(strType);

            foreach (XmlNode node in xn.ChildNodes)
            {
                if (node.Name == strKey)
                {
                    strValue = node.InnerText;
                    break;
                }
            }
            return strValue;
        }
    }
}

